package controller.day04;

import entity.User;
import service.UserService;
import service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "MyServlet", value = "/MyServlet")
public class MyServlet extends HttpServlet {
    private UserService userService =new UserServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 获得页面的参数
        String idStr = request.getParameter("id");
        Integer id = Integer.valueOf(idStr);

        //2. 调用service
        User user = userService.getById(id);

        //3.  将当前user 对象的信息 绑定到request中
        request.setAttribute("myuser", user);

        //4. 页面跳转
        request.getRequestDispatcher("/day04/myjsp.jsp").forward(request,response);
    }
}
